﻿using System.Windows;
using System.Windows.Input;

namespace TeaLightV5.Foundation.UX.WinPhone.Controls
{
    public class StackPanel : System.Windows.Controls.StackPanel
    {
        public StackPanel()
        {

            Tap += DoTapEvent;
        }

        void DoTapEvent(object sender, GestureEventArgs e)
        {
            DoTapCommand();            
        }

        static StackPanel()
        {
            TapCommandProperty = DependencyProperty.Register("TapCommand", typeof(ICommand), typeof(StackPanel),
                new PropertyMetadata(null));
            TapCommandParameterProperty = DependencyProperty.Register("TapCommandParameter", typeof(object),
                typeof(StackPanel), new PropertyMetadata(null));
        }

        public readonly static DependencyProperty TapCommandProperty;

        public readonly static DependencyProperty TapCommandParameterProperty;


        public ICommand TapCommand
        {
            get
            {
                return (ICommand)base.GetValue(TapCommandProperty);
            }
            set
            {
                base.SetValue(TapCommandProperty, value);
            }
        }

        public object TapCommandParameter
        {
            get
            {
                return base.GetValue(TapCommandParameterProperty);
            }
            set
            {
                base.SetValue(TapCommandParameterProperty, value);
            }
        }

        private void DoTapCommand()
        {
            ICommand tapCommand = TapCommand;
            if (tapCommand != null)
            {
                tapCommand.Execute(TapCommandParameter);
            }
        }

    }
}
